﻿<UserControl x:Class="DiagramDesigner.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:s="clr-namespace:DiagramDesigner"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="550" d:DesignWidth="750">

    <UserControl.Resources>

        <!-- ResizeDecorator Template -->
        <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="ContentControl">
            <Grid>
                <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
                <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
                       VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
                       VerticalAlignment="Top" HorizontalAlignment="Right"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </Grid>
        </ControlTemplate>

        <!-- RotateDecorator Template -->
        <ControlTemplate x:Key="RotateDecoratorTemplate" TargetType="ContentControl">
            <Grid>
                <s:RotateThumb Margin="-18,-18,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <s:RotateThumb Margin="0,-18,-18,0" VerticalAlignment="Top" Grid.Column="1" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Right">
                    <s:RotateThumb.RenderTransform>
                        <RotateTransform Angle="90" />
                    </s:RotateThumb.RenderTransform>
                </s:RotateThumb>
                <s:RotateThumb Margin="0,0,-18,-18" HorizontalAlignment="Right" VerticalAlignment="Bottom" >
                    <s:RotateThumb.RenderTransform>
                        <RotateTransform Angle="180" />
                    </s:RotateThumb.RenderTransform>
                </s:RotateThumb>
                <s:RotateThumb Margin="-18,0,0,-18" VerticalAlignment="Bottom" HorizontalAlignment="Left" UseLayoutRounding="False" d:LayoutRounding="Auto">
                    <s:RotateThumb.RenderTransform>
                        <RotateTransform Angle="270" />
                    </s:RotateThumb.RenderTransform>
                </s:RotateThumb>
            </Grid>
        </ControlTemplate>


        <!-- Designer Item Template-->
        <Style x:Key="DesignerItemStyle" TargetType="ContentControl">
            
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate  TargetType="ContentControl">
                        <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                            <s:MoveThumb/>
                            <ContentControl x:Name="resizeDecorator" Template="{StaticResource ResizeDecoratorTemplate}"/>
                            <ContentControl x:Name="rotateDecorator" Template="{StaticResource RotateDecoratorTemplate}"/>
                            <ContentPresenter Content="{TemplateBinding Content}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Canvas>
        <ContentControl Width="130"
                    MinWidth="50"
                    Height="130"
                    MinHeight="50"
                    Canvas.Top="150"
                    Canvas.Left="150"
                    Style="{StaticResource DesignerItemStyle}" >

        	<Path Fill="Blue"
        		Data="M 0,5 5,0 10,5 5,10 Z"
        		Stretch="Fill"
        		IsHitTestVisible="False" />
        </ContentControl>
        <ContentControl Width="130"
                    MinWidth="50"
                    Height="130"
                    MinHeight="50"
                    Canvas.Top="150"
                    Canvas.Left="470"
                    Style="{StaticResource DesignerItemStyle}">

            <Ellipse Fill="Red" IsHitTestVisible="False" Stretch="Fill"/>
        </ContentControl>
    </Canvas>
</UserControl>
